﻿<Window x:Uid="MainWindow" x:Class="WorkRecorder.MainWindow" xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"  
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:converters="clr-namespace:WorkRecorder.Helpers.Converters"   
        xmlns:local="clr-namespace:WorkRecorder"
        Title="MainWindow" Height="710" MaxWidth="800" Width="800">
    <Window.CommandBindings>        
        <CommandBinding x:Uid="CommandBinding_1" Command="local:MyCustomCommand.CanStartCommand" CanExecute="CanExecuteStart" Executed="StartExecuted" />
        <CommandBinding x:Uid="CommandBinding_2" Command="local:MyCustomCommand.CanStopCommand" CanExecute="CanExecuteStop" Executed="StopExecuted" />
        <CommandBinding x:Uid="CommandBinding_3" Command="local:MyCustomCommand.CanSaveCommand" CanExecute="CanExecuteSave" Executed="SaveExecuted" />
        <CommandBinding x:Uid="CommandBinding_4" Command="local:MyCustomCommand.CanClearCommand" CanExecute="CanExecuteClear" Executed="ClearExecuted" />
        <CommandBinding x:Uid="CommandBinding_5" Command="local:MyCustomCommand.LanguageItemSelectionCommand" CanExecute="CanExecuteLanguageItemSelection" Executed="LanguageItemSelectionExecuted" />
        <CommandBinding x:Uid="CommandBinding_6" Command="local:MyCustomCommand.ThemeItemSelectionCommand" CanExecute="CanExecuteThemeItemSelection" Executed="ThemeItemSelectionExecuted" />
    </Window.CommandBindings>
    
    
    <Window.Resources>
        <converters:ListboxRowNumConverter x:Uid="converters:ListboxRowNumConverter_1" x:Key="rowNumConv" />
        <converters:CollectionCountConverter x:Uid="converters:CollectionCountConverter_1" x:Key="colCountConv" />
        <!--<converters:DateTimeConverter x:Uid="converters:DateTimeConverter_1" x:Key="dateTimeConverter" />-->
        <converters:TimeSpanConverter   x:Uid="converters:TimeSpanConverter_1" x:Key="timeSpanConverter" />
    </Window.Resources>
	
	
    <Grid x:Uid="Grid_1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition x:Uid="ColumnDefinition_1" Width="360" />
            <ColumnDefinition x:Uid="ColumnDefinition_2" Width="*" />   
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition x:Uid="RowDefinition_1" Height="30" />
            <RowDefinition x:Uid="RowDefinition_2" Height="365"/>
            <RowDefinition x:Uid="RowDefinition_3" Height="*"/>
      
        </Grid.RowDefinitions>
 
        <!-- Chart popup -->
        <ContentControl x:Uid="ContentControl_1" Grid.Row="0" Grid.Column="0"    Grid.ColumnSpan="2">
            <Popup x:Uid="chartPopup" x:Name="chartPopup"    >
                <Border x:Uid="Border_1" BorderBrush="Red" BorderThickness="1" >
                    <StackPanel x:Uid="StackPanel_1" Orientation="Vertical"  Background="Transparent" >
                    <ContentControl x:Uid="ContentControl_2" HorizontalContentAlignment="Center">
                        <Button  x:Uid="popupCloseButton" x:Name="popupCloseButton"  Foreground="White" FontWeight="Bold" FontSize="16" Click="popupCloseButton_Click" Content="Close chart (X)"  Style="{DynamicResource PopupCloseButtonStyle}"     />
  
                    </ContentControl>
                        <ContentControl x:Uid="ContentControl_3"  > 
                        <chartingToolkit:Chart   x:Uid="chartingToolkit:Chart_1" Width="600" Height="400"       FontSize="18"   >
                                <chartingToolkit:PieSeries x:Uid="workHistoryChartPopup" x:Name="workHistoryChartPopup" Background="Transparent"     ItemsSource="{Binding History}" IndependentValueBinding="{Binding WorkType, Mode=TwoWay}"  DependentValueBinding="{Binding WorkTypeCount, Mode=TwoWay}"  ToolTip="{Binding WorkTypeCount, Mode=TwoWay}"  >
                            </chartingToolkit:PieSeries>
                        </chartingToolkit:Chart>
                    </ContentControl>
                </StackPanel>
                </Border>
            </Popup>
 
 
        </ContentControl>

        <!-- Menu bar -->
        <ContentControl x:Uid="ContentControl_4" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2">
            <Menu x:Uid="Menu_1" >
                <MenuItem x:Uid="MenuItem_1" Header="File">
                <MenuItem x:Uid="MenuItem_2" Header="Load data" Click="loadHistoryButton_Click"></MenuItem>
                <MenuItem x:Uid="MenuItem_3" Header="Exit" Click="exitProgram_Click"></MenuItem>
            </MenuItem>
                <MenuItem x:Uid="MenuItem_4" Header="Settings">
                    <MenuItem x:Uid="MenuItem_5" Header="Theme"   x:Name="themeMenu" ItemsSource="{Binding Source={StaticResource supportedThemesDataProvider}, XPath=Theme}">
 
                        <MenuItem.ItemContainerStyle  >
                            
                            <Style x:Uid="Style_2" TargetType="MenuItem" >
                                <Setter x:Uid="Setter_1" Property="Header" Value="{Binding XPath=@name}"/>
                                <Setter x:Uid="Setter_2" Property="IsCheckable" Value="True"/>
                                <Setter x:Uid="Setter_3" Property="Command" Value="local:MyCustomCommand.ThemeItemSelectionCommand" />
                                <!--<Setter Property="CommandTarget" Value="{Binding RelativeSource={RelativeSource  AncestorType=MenuItem}}"/>-->
                                <Setter x:Uid="Setter_4" Property="CommandParameter" Value="{Binding RelativeSource={RelativeSource Self}}"/>
                            </Style>
                        </MenuItem.ItemContainerStyle>
                    </MenuItem>
                    <MenuItem x:Uid="MenuItem_6"  x:Name="languageMenuItem" Header="Language"    ItemsSource="{Binding Source={StaticResource supportedLanguagesDataProvider}, XPath=Language}"   >
                        <MenuItem.ItemContainerStyle  >
                            <Style x:Uid="Style_3" TargetType="MenuItem" >
                                <Setter x:Uid="Setter_5" Property="Header" Value="{Binding XPath=@name}"/>
                                <Setter x:Uid="Setter_6" Property="IsCheckable" Value="True"/>
                                <Setter x:Uid="Setter_7" Property="Command" Value="local:MyCustomCommand.LanguageItemSelectionCommand" />
                                <Setter x:Uid="Setter_8" Property="CommandParameter" Value="{Binding RelativeSource={RelativeSource Self}}"/>
                            </Style>
                        </MenuItem.ItemContainerStyle>
                    </MenuItem>
            </MenuItem>
                <MenuItem x:Uid="MenuItem_7" Header="Help">
                <MenuItem x:Uid="MenuItem_8" Header="About" Click="about_Click"></MenuItem>
            </MenuItem>
        </Menu>
        </ContentControl>

        <!-- Chart content -->
        <ContentControl x:Uid="ContentControl_5" Grid.Column="1" Grid.Row="1" Margin="10,05,10,0" HorizontalContentAlignment="Center" >
            <GroupBox  x:Uid="statisticsGroupBox" Height="Auto"   Header="Statistics"      Name="statisticsGroupBox"   Width="Auto">
                <Grid x:Uid="Grid_2" Height="330">
                    <Grid.ColumnDefinitions>
                    <ColumnDefinition x:Uid="ColumnDefinition_3" Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions >
                    <RowDefinition x:Uid="RowDefinition_4" Height="*" /> 
                </Grid.RowDefinitions>
                <StackPanel  x:Uid="StackPanel_2" Grid.Row="0" Grid.Column="0">
                        
                        <chartingToolkit:Chart Foreground="Black" x:Uid="pieChart" x:Name="pieChart" BorderThickness="0" MouseLeftButtonDown="pieChart_MouseLeftButtonDown" Margin="0,0,0,0"      Height="320" FontSize="16"   >
                        <chartingToolkit:PieSeries   x:Uid="workHistoryChart" x:Name="workHistoryChart"  ItemsSource="{Binding History}" IndependentValueBinding="{Binding WorkType, Mode=TwoWay}"  DependentValueBinding="{Binding WorkTypeCount, Mode=TwoWay}"  ToolTip="{Binding WorkTypeCount, Mode=TwoWay}"  >

                        </chartingToolkit:PieSeries>

                    </chartingToolkit:Chart>

                </StackPanel>
                </Grid>
            </GroupBox>
        </ContentControl>

        <!-- Create new record content -->
        <ContentControl x:Uid="ContentControl_6" Grid.Column="0" Grid.Row="1" Margin="10,05,0,0" HorizontalContentAlignment="Center" >
            <GroupBox    x:Uid="recordGroupBox" Header="Create new record"  Height="Auto"    Name="recordGroupBox" VerticalAlignment="Top" Width="Auto">
            
                <Grid  x:Uid="Grid_3" Height="330" >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition x:Uid="ColumnDefinition_4" Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions >
                        <RowDefinition x:Uid="RowDefinition_5" Height="55" />
                        <RowDefinition x:Uid="RowDefinition_6" Height="195" />
                        <RowDefinition x:Uid="RowDefinition_7" Height="30" />
                        <RowDefinition x:Uid="RowDefinition_8" Height="40" />
                    </Grid.RowDefinitions>

                    <StackPanel x:Uid="StackPanel_3" Orientation="Vertical" Grid.Column="0" Grid.Row="0" Margin="0,05,0,0">
                        <Label x:Uid="Label_1" Content="Work type:" />
                        <ComboBox x:Uid="workTypeComboBox" x:Name="workTypeComboBox" SelectedItem="{Binding MyWorkType, Mode=TwoWay}"       ItemsSource="{Binding Source={StaticResource workTypesDataProvider}, XPath=WorkType/@name}" />
                    </StackPanel>

                    <StackPanel x:Uid="StackPanel_4" Orientation="Vertical" Grid.Column="0" Grid.Row="1" Margin="0,05,0,0">
                        <Label x:Uid="Label_2" Content="Comments:"  />
                        <TextBox x:Uid="commentsTextBox" x:Name="commentsTextBox" Text="{Binding MyComments, Mode=TwoWay}"   Height="165" AcceptsReturn="True" AcceptsTab="True"  TextWrapping="WrapWithOverflow" ScrollViewer.HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" />
                    </StackPanel>
                    
                    <StackPanel x:Uid="StackPanel_5" Orientation="Horizontal" Grid.Column="0" Grid.Row="2" Margin="0,0,0,0">
                        <StackPanel x:Uid="StackPanel_6" Orientation="Horizontal" Width="165">
                            <Label   x:Uid="Label_3" Content="Time started:"  />
                            <Label   x:Uid="startTimeLabel" Margin="2,0,0,0" IsEnabled="False" VerticalContentAlignment="Center"  BorderThickness="0"  x:Name="startTimeLabel"     Content="{Binding MyStartTime, Mode=TwoWay}" ContentStringFormat="{}{0:t}" />
                        </StackPanel>
                        <StackPanel x:Uid="StackPanel_7" Orientation="Horizontal" Margin="20,0,0,0">
                            <Label x:Uid="Label_4" Content="Time elapsed:"/>
                            <Label x:Uid="timeElapsedLabel" Margin="2,0,0,0" x:Name="timeElapsedLabel" IsEnabled="False" VerticalContentAlignment="Center"  BorderThickness="0" Content="{Binding MyTimeElapsed, Mode=TwoWay}"  />
                        </StackPanel>
                    </StackPanel>
                    
                    <StackPanel x:Uid="StackPanel_8" Orientation="Horizontal" Grid.Column="0" Grid.Row="3" Margin="0,05,0,0">
                        <Button x:Uid="startButton" x:Name="startButton" Margin="08,0,0,0"  
                                Command="local:MyCustomCommand.CanStartCommand" 
                                CommandTarget="{Binding ElementName=commentsTextBox}"
                                CommandParameter="{Binding ElementName=commentsTextBox, Path=Text}"
                                Content="Start work" />
                        <Button x:Uid="stopButton" x:Name="stopButton" Margin="08,0,0,0"   
                                Command="local:MyCustomCommand.CanStopCommand"                                    
                                CommandParameter="{Binding ElementName=startButton, Path=Command}"
                                Content="Stop work" />
                        <Button  x:Uid="Button_1" Margin="45,0,0,0" 
                                 Command="local:MyCustomCommand.CanClearCommand"      
                                 CommandParameter="{Binding ElementName=commentsTextBox, Path=Text}"
                                 Content="Clear fields" />
                        <Button  x:Uid="Button_2" Margin="08,0,0,0" 
                                 Command="local:MyCustomCommand.CanSaveCommand"   
                                 CommandTarget="{Binding ElementName=commentsTextBox}"
                                 CommandParameter="{Binding ElementName=commentsTextBox, Path=Text}"
                                 Content="Save record" />
                    </StackPanel>
                    <!--<ListBox x:Name="workTypesListBox"  Grid.Column="0" Grid.Row="0" ScrollViewer.VerticalScrollBarVisibility="Visible"    ItemsSource="{Binding Source={StaticResource workTypesDataProvider}, XPath=WorkType}" >
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Label   Content="{Binding XPath=@name}" />
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>-->
 

                </Grid>
                

           
            </GroupBox>
            
        </ContentControl>

        <!-- Record list content -->
        <ContentControl x:Uid="ContentControl_7" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" >
            <Grid x:Uid="Grid_4">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition x:Uid="ColumnDefinition_5" Width="350" />
                    <ColumnDefinition x:Uid="ColumnDefinition_6" Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition x:Uid="RowDefinition_9" Height="50" />                    
                    <RowDefinition x:Uid="RowDefinition_10" Height="*" />
                </Grid.RowDefinitions>                
                
                <ContentControl  x:Uid="ContentControl_8" Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="0" Margin="0,20,0,0">
                    <Label x:Uid="Label_5" VerticalContentAlignment="Bottom" Margin="05,0,0,0" Content="Work history:" />
                </ContentControl>

                <ContentControl x:Uid="ContentControl_9" Grid.Column="1" Grid.Row="0"  Margin="0,20,05,0">
                    <StackPanel x:Uid="StackPanel_9" HorizontalAlignment="Right"   Orientation="Horizontal">
                        <Button x:Uid="loadHistoryButton" x:Name="loadHistoryButton" Click="loadHistoryButton_Click" Content="Load history"    Width="75" />
                        <Button x:Uid="deleteAllButton" x:Name="deleteAllButton"   Click="deleteAllButton_Click"    Margin="10,0,0,0"      Content="Delete all history" />
                    </StackPanel>
                </ContentControl>

                <ListView  x:Uid="recordsListView" x:Name="recordsListView" Margin="0,05,0,0"      Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" ItemsSource="{Binding RecordSet, Mode=TwoWay}" >
                    <ListView.View>
                        <GridView x:Uid="GridView_1">
                            <GridViewColumn x:Uid="GridViewColumn_1" Header=""  Width="28" >
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate x:Uid="DataTemplate_1" >
                                        <Button x:Uid="deleteRecordButton" ToolTip="Delete record" Foreground="Red" FontWeight="Bold"   HorizontalContentAlignment="Center" x:Name="deleteRecordButton" Click="deleteRecord_Click" BorderBrush="Transparent"  Background="Transparent" Padding="2" FontSize="13" FontFamily="Arial"   Content="X"   DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}} }" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn   x:Uid="GridViewColumn_8" Header=""  Width="28" >
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate x:Uid="DataTemplate_3">
                                        <Button    x:Uid="loadRecordButton" ToolTip="Load record" Foreground="Green" FontWeight="Bold"    x:Name="loadRecordButton"  HorizontalContentAlignment="Center"  VerticalContentAlignment="Center"  BorderBrush="Transparent" Click="loadRecordButton_Click"  Background="Transparent" Padding="1" FontSize="20"  FontFamily="Arial"     DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}} }" >
                                            <Image x:Uid="Image_1" Width="15" Height="15" Stretch="UniformToFill" Source="ConfigurationFiles/images/onarrow.png"/>                      		
 							            </Button>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn x:Uid="GridViewColumn_2" Header="#"  Width="35" DisplayMemberBinding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}} ,  
                             Converter={StaticResource rowNumConv}}" />
                            <GridViewColumn x:Uid="GridViewColumn_3" Header="Date" Width="100"  DisplayMemberBinding="{Binding StartTime, StringFormat=d, Mode=TwoWay}" ></GridViewColumn>
                            <GridViewColumn x:Uid="GridViewColumn_4" Header="Start Time" Width="100"  DisplayMemberBinding="{Binding StartTime, StringFormat=t, Mode=TwoWay}" ></GridViewColumn>

                            <GridViewColumn x:Uid="GridViewColumn_5" Header="Time Elapsed" Width="100"    DisplayMemberBinding="{Binding TimeElapsed,  Converter={StaticResource timeSpanConverter},  Mode=TwoWay}" ></GridViewColumn>
                            <GridViewColumn x:Uid="GridViewColumn_6" Header="Type" Width="100"  DisplayMemberBinding="{Binding RType, Mode=TwoWay}" ></GridViewColumn>
                            <GridViewColumn x:Uid="GridViewColumn_7" Header="Notes" Width="275"  >
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate x:Uid="DataTemplate_2">
                                        <Expander  x:Uid="notesExpander" x:Name="notesExpander" Width="265"  Header="Expand to see notes"  IsExpanded="False"  >
                                            <!--<Trigger Property="IsMouseOver" Value="False">
                                        <Setter  Property="Visibility" Value="Collapsed" />
                                    </Trigger>-->
                                            <ContentControl x:Uid="ContentControl_10">
                                                <StackPanel x:Uid="StackPanel_10">
                                                <TextBox x:Uid="TextBox_1" Height="85" Width="255" AcceptsReturn="True" AcceptsTab="True"  TextWrapping="WrapWithOverflow" ScrollViewer.HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" Text="{Binding Comments, Mode=TwoWay}" />
                                                    <Button x:Uid="editCommentsSaveButton" x:Name="editCommentsSaveButton" Click="editCommentsSaveButton_Click" Content="Save changes" />
                                                </StackPanel>
                                            </ContentControl>
                                        </Expander>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                </ListView>
            </Grid>
        </ContentControl>
        
    </Grid>
</Window>

    